package top.go2do.common.utils;

import java.security.SecureRandom;

/**
 * @Description
 * @Author xingyj
 * @CreateTime 2025/3/17 11:33
 */
public class MySecureRandomStringUtils {
    private static final SecureRandom RANDOM = new SecureRandom();
    private static final String CHAR_SET =
            "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";

    /**
     * 生成指定长度的安全随机字符串
     * @param length
     * @return
     */
    public static String generate(int length) {
        return RANDOM.ints(length, 0, CHAR_SET.length())
                .mapToObj(i -> CHAR_SET.charAt(i))
                .collect(StringBuilder::new,
                        StringBuilder::append,
                        StringBuilder::append)
                .toString();
    }

}
